package com.soft.mainsite.module.city.web;

import com.soft.mainsite.common.domain.RestResponse;
import com.soft.mainsite.module.city.dto.CityDto;
import com.soft.mainsite.module.city.entity.City;
import com.soft.mainsite.module.city.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * CityController.java 此类用于城市控制层
 *
 * @author:李昭阳
 * @date:2019/4/12 0012
 * @remark:
 */
@Controller
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    /**
     * 获取省份列表
     * @return
     */
    @RequestMapping("/getProviceList")
    @ResponseBody
    public RestResponse<List<CityDto>> getProviceList(){
        List<CityDto> proviceList = cityService.getProviceList();
        return RestResponse.success(proviceList);
    }

    /**
     * 通过省份获取城市列表
     * @param provinceCode
     * @return
     */
    @RequestMapping("/getCityListByProvice")
    @ResponseBody
    public RestResponse<List<CityDto>> getCityListByProvice(Integer provinceCode){
        List<CityDto> cityList = cityService.getCityListByProvice(provinceCode);
        return RestResponse.success(cityList);
    }

    /**
     * 获取站点城市列表
     * @return
     */
    @RequestMapping("/getSiteCityList")
    @ResponseBody
    public RestResponse<List<CityDto>> getSiteCityList(){
        List<CityDto> siteCityList = cityService.getSiteCityList();
        return RestResponse.success(siteCityList);
    }

    /**
     * 根据城市父编码查询城市区县列表
     *
     * @param cityCode
     * @return
     */
    @RequestMapping("/getDistrictListByCity")
    @ResponseBody
    public RestResponse<List<City>> getDistrictListByCity(Integer cityCode){
        List<City> cityDistrictList = cityService.getCityDistrictByCityParentCode(cityCode);
        return RestResponse.success(cityDistrictList);
    }
}
